import 'dart:typed_data';

import 'package:dartx/dartx.dart';

extension Hex on List<int> {
  String toHex([String separator = ""]) {
    return _hexEncode(this, separator);
  }
}

extension byte on int {
  Uint8List bytes({Endian endian = Endian.little, int bits = 2}) {
    var list = toBytes(endian).sublist(0, bits);
    // print("int to byte:${list.map((e) => e.toRadixString(16).padLeft(2, '0')).joinToString(separator: "_")}");
    return list;
  }
}

String _hexEncode(List<int> numbers, [String separator = ""]) {
  return numbers
      .map((n) => (n & 0xFF).toRadixString(16).padLeft(2, '0'))
      .join(separator);
}
